/*
题目描述：和为 s 的连续整数序列
输入一个正数 s ，打印出所有和为 s 的连续正数序列
方法：滑动窗口
 */
public class E57_2 {
    public static void main(String[] args) {
        FindContinuousSequence(15);
    }

    public static void FindContinuousSequence(int sum){
        if(sum < 3){
            return;
        }
        int small = 1;
        int big = 2;
        int middle = (1 + sum) / 2;
        int curSum = small + big;

        while(small < middle){
            if(curSum == sum){
                PrintContinuousSequence(small, big);
            }
            while(curSum > sum && small < middle){
                curSum -= small;
                small ++;
                if(curSum == sum){
                    PrintContinuousSequence(small, big);
                }
            }
            big ++;
            curSum += big;
        }
    }

    public static void PrintContinuousSequence(int small, int big){
        for(int i = small; i <= big; i++){
            System.out.print(i + " ");
        }
        System.out.println();
    }
}
/*
1 2 3 4 5
4 5 6
7 8
 */